import React, { useRef } from "react"

const ChildComp = () => {
  return (
    <div>
      <h1>Child Component</h1>
    </div>
  )
}

const CompForwardRef = () => {
  const childRef = useRef(null)

  const getChildRef = () => {
    console.log("childRef", childRef.current)
  }

  return (
    <div>
      <h1>Parent Component</h1>
      <div>
        <button onClick={getChildRef}>点击获取子组件 ref </button>
      </div>
      <ChildComp ref={childRef} />
    </div>
  )
}

export default CompForwardRef
